#!/bin/bash

# Usage:
#       make_pem {cert_file} {private_key_file}
# Example:
#       make_pem aps_developer_indetity.cer aps_developer_identity.p12 appkey
mkdir -p temp
openssl pkcs12 -in "$2" -out temp/key-enc.pem -nodes
openssl rsa -in temp/key-enc.pem -out temp/key.pem
openssl x509 -inform der -in "$1" -out temp/cert.pem

if [ "$4" = "dev" ]; 
then
    cat temp/cert.pem temp/key.pem > /opt/etcloud/apn_server/etc/dev_cert_file/"$3".pem
else
    cat temp/cert.pem temp/key.pem > /opt/etcloud/apn_server/etc/pro_cert_file/"$3".pem
fi
rm -rf temp
